﻿using Newtonsoft.Json;
using System.Collections.Generic;
using Zdap.Common;

namespace Zdap.XCode
{
    public class PageResponseContext2<T> : PageResponseContext<T> where T : class
    {
        //
        // 摘要:
        //     设置成功
        //
        // 参数:
        //   data:
        public PageResponseContext2<T> SetSuccess(IEnumerable<T> data, long recordCount, Pager page)
        {
            Code = 200;
            Msg = "";
            Data = data;
            RecordCount = recordCount;
            PageIndex = page.PageIndex;
            PageSize = page.PageSize;
            return this;
        }

        //
        // 摘要:
        //     设置成功
        //
        // 参数:
        //   data:
        public PageResponseContext2<T> SetSuccess(IEnumerable<T> data, Pager page)
        {
            Code = 200;
            Msg = "";
            Data = data;
            RecordCount = page.TotalCount;
            PageIndex = page.PageIndex;
            PageSize = page.PageSize;
            return this;
        }

        //
        // 摘要:
        //     设置成功
        //
        // 参数:
        //   data:
        public PageResponseContext2<T> SetSuccess(IEnumerable<T> data, Pager page, List<ColumnDataModel> columnDatas = null)
        {
            Code = 200;
            Msg = "";
            Data = data;
            RecordCount = page.TotalCount;
            PageIndex = page.PageIndex;
            PageSize = page.PageSize;
            if (columnDatas != null)
                ColumnDatas = columnDatas;
            return this;
        }

        /// <summary>
        /// 设置失败
        /// </summary>
        /// <param name="response"></param>
        public virtual PageResponseContext2<T> SetError(BaseResponse response)
        {
            SetError(response.Msg, response.Code);
            return this;
        }

        /// <summary>
        /// 设置失败
        /// </summary>
        /// <param name="response"></param>
        public virtual PageResponseContext2<T> SetError(string msg, int code = 400)
        {
            base.SetError(msg, code);
            return this;
        }

        /// <summary>
        /// 列头信息
        /// </summary>
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        public List<ColumnDataModel> ColumnDatas { get; set; }
    }
}